Repository navigation
fix: recover from mid-stream upstream truncations (#413 relaxation + continuation retry) - #891
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-891Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr891.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #891 verified — ready for human merge. Per the [PR] protocol I did not redo the work: pulled the branch, reviewed the full diff against current master, and checked CI. Branch state: CI: green 8/8 on head Diff review (
One nit found and fixed directly on the branch: three comment lines in the new block carried a stray extra leading space ( No blocking issues. The follow-ups listed in the body (stateful-wire framing recovery, weak-overflow blind spot, visibility-marker suppression) remain intentionally out of scope. 中文摘要:已核对分支并逐行 review——#413 门放宽与续写重试均正确限定在 openai wire、双独立一次性预算、nudge 不污染会话状态,CI 8/8 全绿且既有 anthropic/responses 守卫测试原样通过;review 中发现注释块三行多一个前导空格,已在 PR 分支直接补 commit 修复(10f2a83),无阻塞问题,可以合并。 |
[bot] 🏷 Follow-up: CI on the updated head |
…continuation retry) Field data (relay -> GLM via ACP client; 6.5h, 30+ rounds) contributed by the issue reporter in #862: the reasoning-only-prefix shape errored 7x across 5 sessions pre-fix; the visible-text shape (long final reports) had no recovery path at all. - #413 gate relaxed from !forwardedAny to also cover invisible-only prefixes (reasoning/meta): a thinking-then-cut stream now retries instead of erroring. Scoped to the openai wire, whose chunks are stateless. Stateful wires keep the strict nothing-forwarded condition: once anything was forwarded their per-response identity framing is already live (anthropic message_start with open content blocks, responses response.created - #440's single-created invariant), and a re-fetched response would emit it a second time. - New continuation retry for cuts AFTER visible text reached the client: one re-fetch with an ephemeral nudge quoting the forwarded tail (<=800 chars), asking the model to resume seamlessly without repeating; roundBody updated so any later blind re-fetch carries the continuation context. OpenAI wire only, same framing reason. The nudge never enters coreMessages/session state (same ephemerality as #732's). - Two independent one-shot budgets (truncationRetried / continuationRetried) so both cut orderings self-heal; max 2 extra fetches per request, each logged. Rounds with tool-call fragments keep the plain truncation error (fragment semantics only survive a completed stream). Tests: flip tests/loop-truncation-reasoning.test.ts (old strict-gate assertion); add tests/loop-truncation-continuation.test.ts covering both cut orderings, budget exhaustion, tool-call exclusion, failed-retry fallback, and textProtocol exclusion. Existing #413-T3/T4 (anthropic) and #440-T2 (responses) now guard the wire scoping. Pre-flight on 0.1.117: typecheck clean, 1675/1677 pass (2 skipped), build ok. Closes #862
10f2a83 to
5c5071b
Compare
What
Recovery for the two mid-stream truncation shapes seen with high-reasoning upstreams behind relays (#862, field-validated over 6.5h / 30+ rounds):
0 text + N reasoning) was a hard error — 7 occurrences across 5 sessions in the reporter's logs.roundBodyis updated so any later blind re-fetch also carries the continuation context.Two independent one-shot budgets (
truncationRetried/continuationRetried): max 2 extra fetches per request, each logged, so both cut orderings self-heal. Rounds with tool-call fragments keep the plain truncation error. The nudge never enterscoreMessages/session state (same ephemerality as #732's).Why wire-scoped (review refinement of the contributed patch)
The patch contributed in #862 relaxed the #413 gate to
!forwardedVisibleunconditionally. That is safe on the openai wire (stateless chunks — the reporter's channel), but on stateful wires a re-fetched response would re-emit per-response identity framing that already reached the client:message_startplus open content blocks would be duplicated;response.created— breaking fix: acp-loop zero-side-effect truncation retry + well-formed anthropic error stream (#413) #440's single-created invariant (its T2 test fails against the unconditional relaxation).So the relaxation lands as
(!forwardedAny || (protocol === "openai" && !forwardedVisible)): the original zero-side-effect case stays universal, the new invisible-prefix case is openai-only, and the continuation retry is openai-only for the same reason (visible text implies the identity framing already went out). Existing#413-T3/T4(anthropic) and#440-T2(responses) tests now pass unchanged and guard this scoping. Behavior on the reporter's channel is identical to their deployed patch.Tests
tests/loop-truncation-reasoning.test.ts(asserted the old strict gate).tests/loop-truncation-continuation.test.ts: both cut orderings (visible→invisible→clean, invisible→visible→clean), budget exhaustion → surfaced error, tool-call rounds excluded, failed-retry fallback,textProtocolexclusion.Follow-ups (reported in-thread, intentionally not in this PR)
input/window < 0.9never counts, so conservative windows never learn) — real samples collected by the reporter; human to file the issue.MARKER_INTEGRITY_NOTEwording — separate PRs, green-lit in-thread.Based on the field diagnosis and initial patch contributed in #862.
Closes #862